﻿<Serializable()>
Public Class ClientCredential
    Private Shared TokenUrl As String = "https://api.yixin.im/cgi-bin/token?grant_type=client_credential&appid={0}&secret={1}"

    Public Property access_token() As String

    Public Property expires_in() As Integer

    Public Property [error]() As ReturnCode

    Friend Shared Function GetCredential(appId As String, appSecret As String) As ClientCredential
        Dim json As String = Util.HttpGet2(String.Format(ClientCredential.TokenUrl, appId, appSecret))
        Dim cred As ClientCredential
        If json.IndexOf("errcode") >= 0 Then
            cred = New ClientCredential()
            cred.[error] = Util.JsonTo(Of ReturnCode)(json)
        Else
            cred = Util.JsonTo(Of ClientCredential)(json)
        End If
        Return cred
    End Function
End Class
